package cn.hucode.chapter2.controller;

import cn.hucode.chapter2.model.Customer;
import cn.hucode.chapter2.service.CustomerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author jiajian
 * @date 2016/12/1
 */

@WebServlet("/customer")
public class CustomerServlet extends HttpServlet {
    private CustomerService customerService;


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Customer> list = customerService.getList("");
        req.setAttribute("customerList", list);
        req.getRequestDispatcher("/WEB-INF/view/customer.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO: 2016/12/1
    }

    @Override
    public void init() throws ServletException {
        customerService = new CustomerService();
    }
}
